package com.wuliu.system.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wuliu.common.exception.ServiceException;
import com.wuliu.common.utils.DateUtils;
import javax.annotation.Resource;

import com.wuliu.common.utils.SecurityUtils;
import com.wuliu.system.domain.SysAccount;
import org.springframework.stereotype.Service;
import com.wuliu.system.mapper.BasCompanyMapper;
import com.wuliu.system.domain.BasCompany;
import com.wuliu.system.service.IBasCompanyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 客户资料Service业务层处理
 * 
 * @author realue
 * @date 2023-10-24
 */
@Service
public class BasCompanyServiceImpl extends ServiceImpl<BasCompanyMapper, BasCompany> implements IBasCompanyService
{
    @Resource
    private BasCompanyMapper basCompanyMapper;

    /**
     * 查询客户资料
     * 
     * @param id 客户资料主键
     * @return 客户资料
     */
    @Override
    public BasCompany selectBasCompanyById(String id)
    {
        return basCompanyMapper.selectBasCompanyById(id);
    }

    /**
     * 查询客户资料列表
     * 
     * @param basCompany 客户资料
     * @return 客户资料
     */
    @Override
    public List<BasCompany> selectBasCompanyList(BasCompany basCompany)
    {
        return basCompanyMapper.selectBasCompanyList(basCompany);
    }

    /**
     * 新增客户资料
     * 
     * @param basCompany 客户资料
     * @return 结果
     */
    @Override
    public int insertBasCompany(BasCompany basCompany)
    {
        long count = basCompanyMapper.selectCount(new LambdaQueryWrapper<BasCompany>()
                .eq(BasCompany::getSysAccount, basCompany.getSysAccount())
                .eq(BasCompany::getCompNo, basCompany.getCompNo()));
        if (count > 0) {
            throw new ServiceException("客户编号已存在");
        }
        basCompany.setCreateTime(DateUtils.getNowDate());
        return basCompanyMapper.insertBasCompany(basCompany);
    }

    /**
     * 修改客户资料
     * 
     * @param basCompany 客户资料
     * @return 结果
     */
    @Override
    public int updateBasCompany(BasCompany basCompany)
    {
        basCompany.setUpdateTime(DateUtils.getNowDate());
        return basCompanyMapper.updateBasCompany(basCompany);
    }

    /**
     * 批量删除客户资料
     * 
     * @param ids 需要删除的客户资料主键
     * @return 结果
     */
    @Override
    public int deleteBasCompanyByIds(String[] ids)
    {
        return basCompanyMapper.deleteBasCompanyByIds(ids);
    }

    /**
     * 删除客户资料信息
     * 
     * @param id 客户资料主键
     * @return 结果
     */
    @Override
    public int deleteBasCompanyById(String id)
    {
        return basCompanyMapper.deleteBasCompanyById(id);
    }
}
